import {defineStore} from "pinia";
import {reactive} from "vue";
import DictApi from "/@/api/system/DictApi";

export const useDictStore = defineStore("dict", () => {
    const dictStore = reactive<Array<DictState>>([])

    const init = () => {
        DictApi.getDictStore().then(res => {
            Object.assign(dictStore, res.data)
        })
    }
    const getDict = (code: string) => {
        if (dictStore.length == 0) {
            init()
        }
        const dict: DictState |undefined = dictStore.find(item => {
            return item.code === code
        });
        return dict!.items
    }
    return { getDict }
})